import {
    ref
} from 'vue'
export default function (todoListRef) {
    let editingTodoRef = ref(null);
    let editContentRef = ref("");//记录编辑前的数据
    let selectAllKey = ref(false)
    // 编辑时候执行
    const editTodo = (val) => {
        console.log("开始编辑",val);
        editingTodoRef.value = val;
        editContentRef.value = val.content;
    }
    // 编辑完成
    const editDone = (val) => {
        console.log("编辑完成",val);
        // if(val)
        editingTodoRef.value = null
    }
    // 编辑取消
    const editExit = (val) => {
        console.log("编辑推出",val);
        val.content = editContentRef.value;
        editContentRef.value = "";
        editingTodoRef.value = null;
    }
    // 编辑取消
    const editBlur = (val) => {
        console.log("编辑推出",val);
        editingTodoRef.value = null
    }
    // 所有全选
    const selectAll = (val) => {
        console.log("所有全选",val);
        todoListRef.value.forEach(ele => {
            ele.completed = selectAllKey
        });

    }
    return {
        editingTodoRef,
        editTodo,
        editDone,
        editExit,
        editBlur,
        selectAll,
        selectAllKey
    }
}